﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Net.Fan.SmallPig.DataAccess;
using Net.Fan.SmallPig.Common.DBMeta;
using System.Data;

public partial class User_MyInfoEdit : System.Web.UI.Page
{
    string userName;
    protected void Page_Load(object sender, EventArgs e)
    {
        userName = Request.Params["U"];
        if (string.IsNullOrEmpty(userName))
        {
            userName = this.User.Identity.Name;
        }
        else
        {
            if (userName != this.User.Identity.Name)
            {
                PagePermission.CheckIsAdmin(this);
            }
        }

        if (IsPostBack == false)
        {
            DataRow ud = UserDA.GetUserByName(userName);
            labUserName.Text = ud[UserMeta.UserNameField] as string;
            txtTrueName.Text = ud[UserMeta.TrueNameField] as string;
            lstSex.SelectedValue = ud[UserMeta.GenderField] as string;
            txtCompany.Text = ud[UserMeta.CompanyField] as string;
            txtDuty.Text = ud[UserMeta.DutyField] as string;
            txtRemark.Text = ud[UserMeta.RemarkField] as string;
            txtDept.Text = ud[UserMeta.DepartmentField] as string;
            txtOfficeAddress.Text = ud[UserMeta.OfficeAddressField] as string;
            txtOfficeTel.Text = ud[UserMeta.OfficeTelField] as string;
            txtInstantMessager.Text = ud[UserMeta.InstantMessagerField] as string;
        }
    }
    protected void btReg_Click(object sender, EventArgs e)
    {
        UserDA.UpdateBaseInfo(userName, txtTrueName.Text, lstSex.SelectedValue, txtRemark.Text);
        UserDA.UpdateConnectInfo(userName, txtCompany.Text, txtDept.Text, txtDuty.Text, txtInstantMessager.Text, txtOfficeTel.Text, txtOfficeAddress.Text);
        labMessage.Text = "修改成功！";
        Response.Redirect(string.Format("MyInfoEdit.aspx?U={0}", userName));
    }
}
